<template>
  <el-dialog
      :close-on-click-modal="false"
      :visible.sync="searchVisiblelab"
      :before-close="handleClose"
      top="5vh"
    >
    <template slot="title">
        <div :style="titleColor">搜索</div>
      </template>
      <el-form :inline="true" class="demo-form-inline filter">
        <el-form-item label="地点">
          <el-input
            v-model="listQuerySearchlab.fpointName"
            clearable
            class="filter-item"
            placeholder="请输入地点"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            round
            size="medium"
            class="filter-item"
            :style="{background:buttonColor.lookup,color:buttonColor.color}"
            @click="searchFilterlab"
          >查找</el-button
          >
        </el-form-item>
      </el-form>

      <!-- 查询结果 -->
      <el-table
        v-loading="listLoadingSearchlab"
        :data="searchListlab"
        stripe
        element-loading-text="正在查询中。。。"
        border
        fit
        highlight-current-row
        height="300"
      >
        <el-table-column align="center" label="地点" prop="fpointName" />
        <el-table-column
          align="center"
          label="选择"
          class-name="small-padding"
        >
          <template slot-scope="scope">
            <el-button
              :style="{background:buttonColor.confirm,color:buttonColor.color}"
              round
              size="small"
              class="button-margin"
              @click="searchDatalab(scope.row)"
            >确定</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="totalSearchlab > 0"
        :total="totalSearchlab"
        :page.sync="listQuerySearchlab.page"
        :limit.sync="listQuerySearchlab.limit"
        style="padding:14px 10px !important"
        @pagination="getSearchListlab"
      />
    </el-dialog>
</template>

<script>
import Pagination from '@/components/Pagination'
import { listRoom } from '@/api/room'
import {buttonColor,titleColor} from '@/filters/index'
export default {
  name: 'LabDialog',
  components: { Pagination },
  props:{
    searchVisiblelab: {
      required: true,
      type: Boolean
    },
    fsiteNo: {
      required: true,
    },
  },
  data(){
    return{
      titleColor,
      buttonColor,
      selectListlab:[],
      searchListlab: null,
      listLoadingSearchlab: true,
      totalSearchlab: 0,
      listQuerySearchlab: {
        page: 1,
        limit: 20,
        fpointName: undefined,
        sort: 'create_time',
        order: 'desc'
      },
    }
  },
  created(){
     this.getSearchListlab()
  },
  watch: {
    fsiteNo: function() {
      this.getSearchListlab()
    },
  },
  methods:{
     // 地点获取搜索列表
    getSearchListlab() {
      if(this.fsiteNo){
         this.listLoadingSearchlab = true
          const temp = {
            fsiteNo:this.fsiteNo,
            fpointFlag:0,
            page:this.listQuerySearchlab.page,
            limit:this.listQuerySearchlab.limit,
            sort: 'create_time',
            order: 'desc',
            fpointName:this.listQuerySearchlab.fpointName,
          }

          listRoom(temp)
          .then(response => {
            this.searchListlab = response.data.data.list
            this.totalSearchlab = response.data.data.total
              this.listLoadingSearchlab = false
          })
          .catch(() => {
            this.searchListlab = []
            this.totalSearchlab = 0
              this.listLoadingSearchlab = false
          })
      }else{
        this.searchListlab = []
        this.totalSearchlab = 0
        this.listLoadingSearchlab = false
      }


    },

    // 查找
    searchFilterlab() {
      this.listQuerySearchlab.page = 1
      this.getSearchListlab()
    },

    // 确定
    searchDatalab(row) {
     this.$emit('update:searchVisiblelab', false)
      this.$emit('labDialog', { lab: row })
    },

     // 弹窗点击关闭前的回调
    handleClose(){
      this.$emit('update:searchVisiblelab', false)
    }

  },
}
</script>
